const express  = require('express')
const router = express.Router()
const {query} = require('../../db/conn.js')
var url = require('url')
//引入时间模块
const {
	time
} = require('../../config/date.js')
// 三级级路由

// 获取所有留言api 
router.get('/selectAll',async(req,res)=>{
	let { good_id } = req.query
	let sql = "select * from store_liuyan o inner join store_user g on o.u_id=g.u_id where good_id = ?"
	query(sql,[good_id]).then(result=>{
		res.send(JSON.stringify({
			 code:200,
			 msg:'获取成功',
			 data:result
		}))
	})
})


// 写评论
router.post('/add', async (req, res)=>{
    let u_id = req.user.u_id
	let {good_id,textarea} = req.body
	//获取当前时间
	var str = time();
	let sql = "insert into store_liuyan (u_id,good_id,time,textarea) value (?,?,?,?)"
	query(sql,[u_id,good_id,str,textarea]).then(result=>{
		res.send(JSON.stringify({
			code:200,
			msg:'评论成功'
		}))
	})
})

module.exports = router